unit Map_P2;

interface

uses
  SysUtils, Classes, ADODB, DB, DataEngine, Class_P2;

type
  TMap_P2 = class(TDataEngine)
  public
    FTableName: string;
  public
    function ReadDS(AADODst: TADODataSet): TBaseClass; override;
    function GetStrsIndex(ABaseClass: TBaseClass): string; override;

    function GetStrInsert: string; override;
    function GetStrUpdate: string; override;
    function GetStrDelete: string; override;
    procedure SetParameters(ABaseClass: TBaseClass); override;

    function GetNextPDH(P2A: TP2): Integer;
  end;

implementation

{ TMap_P2 }

function TMap_P2.GetNextPDH(P2A: TP2): Integer;
begin
  Result := GetNextID(FTableName, 'PDH', ' AND YUE = ' + IntToStr(P2A.YUE) + ' AND LB = ' + QuotedStr(P2A.LB));
end;

function TMap_P2.GetStrDelete: string;
begin
  Result := '';
end;

function TMap_P2.GetStrInsert: string;
begin
  Result:='INSERT INTO ' + FTableName
         +'(YUE, LB, PDH, FJZS, JZR, XGR, SHR, FCH, PZLY, CURMONTH'
         +', MASTER, DELEGATE, CN, BOOKBY, IMAGEID)'
         +' VALUES'
         +'(:YUE, :LB, :PDH, :FJZS, :JZR, :XGR, :SHR, :FCH, :PZLY, :CURMONTH'
         +', :MASTER, :DELEGATE, :CN, :BOOKBY, :IMAGEID)';
end;

function TMap_P2.GetStrsIndex(ABaseClass: TBaseClass): string;
begin
  with TP2(ABaseClass) do
  begin
    Result := IntToStr(YUE) + '-' + IntToStr(PDH);
  end;
end;

function TMap_P2.GetStrUpdate: string;
begin
  Result:='UPDATE ' + FTableName + ' SET'
         +' FJZS=:FJZS,'
         +' JZR=:JZR,'
         +' XGR=:XGR,'
         +' SHR=:SHR,'
         +' FCH=:FCH,'
         +' PZLY=:PZLY,'
         +' CURMONTH=:CURMONTH,'
         +' MASTER=:MASTER,'
         +' DELEGATE=:DELEGATE,'
         +' CN=:CN,'
         +' BOOKBY=:BOOKBY,'
         +' IMAGEID=:IMAGEID'
         +' WHERE YUE = :YUE'
         +' AND LB = :LB'
         +' AND PDH = :PDH';
end;

function TMap_P2.ReadDS(AADODst: TADODataSet): TBaseClass;
var
  FieldA: TField;
begin
  Result := TP2.Create;
  with TP2(Result) do
  begin
    YUE := AADODst.FieldByName('YUE').AsInteger;
    LB := AADODst.FieldByName('LB').AsString;
    PDH := AADODst.FieldByName('PDH').AsInteger;
    FJZS := AADODst.FieldByName('FJZS').AsInteger;
    JZR := AADODst.FieldByName('JZR').AsString;
    XGR := AADODst.FieldByName('XGR').AsString;
    _SHR := AADODst.FieldByName('SHR').AsString;
    FCH := AADODst.FieldByName('FCH').AsInteger;
    PZLY := AADODst.FieldByName('PZLY').AsString;
    CURMONTH := AADODst.FieldByName('CURMONTH').AsInteger;
    MASTER := AADODst.FieldByName('MASTER').AsString;
    DELEGATE := AADODst.FieldByName('DELEGATE').AsString;
    CN := AADODst.FieldByName('CN').AsString;
    BOOKBY := AADODst.FieldByName('BOOKBY').AsString;

    FieldA := AADODst.FindField('IMAGEID');
    if FieldA <> nil then
    begin
      IMAGEID := FieldA.AsInteger;
    end else
    begin
      IMAGEID := 0;
    end;
  end;
end;

procedure TMap_P2.SetParameters(ABaseClass: TBaseClass);
var
  ObjA: TP2;
begin
  ObjA := TP2(ABaseClass);
  with FADOCmd.Parameters do
  begin
    case FOpType of
      otAdd, otEdit:
      begin
        ParamByName('YUE').Value := ObjA.YUE;
        ParamByName('LB').Value := ObjA.LB;
        ParamByName('PDH').Value := ObjA.PDH;
        ParamByName('FJZS').Value := ObjA.FJZS;
        ParamByName('JZR').Value := ObjA.JZR;
        ParamByName('XGR').Value := ObjA.XGR;
        ParamByName('SHR').Value := ObjA._SHR;
        ParamByName('FCH').Value := ObjA.FCH;
        ParamByName('PZLY').Value := ObjA.PZLY;
        ParamByName('CURMONTH').Value := ObjA.CURMONTH;
        ParamByName('MASTER').Value := ObjA.MASTER;
        ParamByName('DELEGATE').Value := ObjA.DELEGATE;
        ParamByName('CN').Value := ObjA.CN;
        ParamByName('BOOKBY').Value := ObjA.BOOKBY;
        ParamByName('IMAGEID').Value := ObjA.IMAGEID;
      end;
      otDel:
      begin
 
      end;  
    end;
  end;
end;

end.
